<!--
 * @Descripttion: 慢直播列表
 * @Author: wang pingqi
 * @Date: 2021-12-07 11:19:47
 * @LastEditors: wang pingqi
 * @LastEditTime: 2022-07-01 13:46:56
-->
<template>
  <div class="app-container">
    <el-form ref="listFilterRef" :model="list.filter" inline class="list-filter">
      <el-form-item prop="name">
        <el-input
          v-model="list.filter.name"
          placeholder="请输入直播名称搜索"
          clearable
        >
          <i slot="prefix" class="el-input__icon el-icon-search" />
        </el-input>
      </el-form-item>
      <el-form-item prop="equipmentId">
        <el-select v-model="list.filter.equipmentId" clearable placeholder="设备名称搜索" filterable >
          <el-option
            v-for="item in deviceList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item  prop="scenicId">
        <el-select v-model="list.filter.scenicId" clearable placeholder="关联景区搜索" filterable >
          <el-option
            v-for="item in scenicList"
            :key="item.id"
            :disabled="!item.status"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-button @click="reset">重置</el-button>
    </el-form>

    <div class="table-operation">
      <span>
        <AuthButton @click="c" name="新增" />
      </span>
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <form-item-tip
      class="mb10"
      value="该功能配置后只会在微信小程序端生效"
    />
    
    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column align="center" type="index" />
      <el-table-column label="直播名称" prop="name" />
      <el-table-column label="设备名称" prop="equipmentName" />
      <el-table-column label="列表图">
        <template slot-scope="scope">
          <PicViewer :value="scope.row.imgPath" tableCell />
        </template>
      </el-table-column>
      <el-table-column label="简介" prop="introduction"></el-table-column>
      <el-table-column label="关联景区" prop="scenicName"></el-table-column>
      <el-table-column label="创建时间" prop="createTime"></el-table-column>
      <el-table-column label="直播状态" prop="liveStatusName" />
      <!-- <el-table-column label="启用状态" width="80" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="操作">
        <template slot-scope="{ row }">
          <auth-button @click="r({ id: row.id })" name="查看" />
          <auth-button @click="u({ id: row.id })" name="编辑" />
          <auth-button @click="d({ id: row.id })" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="直播名称" prop="name" verify>
          <el-input
            v-model="form.data.name"
            clearable
            maxlength="20"
            show-word-limit
            placeholder="请输入直播名称"
          />
        </el-form-item>
         <el-form-item label="直播房间号" prop="roomId" :rules="roomIdRules">
          <el-input
            v-model.trim="form.data.roomId"
            clearable
            maxlength="9"
            show-word-limit
            placeholder="请输入直播房间号"
          />
        </el-form-item>
        <el-form-item label="简介" prop="introduction" verify>
          <el-input
            v-model="form.data.introduction"
            clearable
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4}"
            maxlength="100"
            show-word-limit
            placeholder="请输入简介"
          />
        </el-form-item>
        <el-form-item label="设备名称" prop="equipmentId" verify>
         <el-select v-model="form.data.equipmentId" clearable placeholder="请选择" filterable >
            <el-option
              v-for="item in deviceList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联景区" prop="scenicId" verify>
         <el-select v-model="form.data.scenicId" filterable placeholder="请选择">
          <el-option
            v-for="item in scenicList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
            :disabled="!item.status"
            >
          </el-option>
        </el-select>
        </el-form-item>
        <el-form-item label="列表图" prop="imgPath" verify>
          <Imgpond valueType="array" v-model="form.data.imgPath" :count="1" />
        </el-form-item>
        <el-form-item label="推流地址" prop="pushUrl" v-if="form.status!='c'">
          <el-input
            v-model="form.data.pushUrl"
            clearable
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4}"
            maxlength="300"
            show-word-limit
            :disabled="form.status!='c'"
            placeholder="请输入推流地址"
          />
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'

export default {
  mixins: [pageMixin],
  setup: () => useAdmateAdapter({
    urlPrefix: 'one-travel-api/slowlive'
  }),
  data () {
    return {
      deviceList : [],
      scenicList : [],
      roomIdRules : {
        required:true, 
        trigger: 'blur',
        validator : (rule, value, callback)=>{
          let reg = /^[0-9]*$/;
          if(!value){
            callback(new Error('必填项'))
          }
          if(!reg.test(value)){
            callback(new Error('请输入数字'))
          }else{
            callback()
          }
        }
      },
    }
  },
  created(){
    this.getDevice();
    this.getScenicList();
  },
  methods: {
   async getDevice(){
      let {data} = await this.$POST('one-travel-api/slowlive/equipment/queryForList');
      this.deviceList = data;
    },
    async getScenicList(){
      let {data} = await this.$POST('one-travel-api/scenic/queryForList');
      this.scenicList = data;
    }
  }
}
</script>

<style lang="scss" scoped>
</style>

